/**
 * Created by Ru on 14/12/16.
 */
var myApp = angular.module('myApp',['ngCookies']);


// myApp.value('test','testvalue')

myApp.controller('findController',['$scope','$http','$location','$interval','$window','$cookieStore',function ($scope,$http,$location,$interval,$window,$cookieStore) {
    console.log('findController loaded');


    $scope.find={};




    $scope.findFault = function () {

        var beginTime =  $("#beginTime").val();
        var endTime = $("#endTime").val();

        if (beginTime != ''){
            $scope.find.beginTime = beginTime;
        }
        if (endTime != ''){
            $scope.find.endTime = endTime
        }
        console.log($scope.find);


        $http.post('../api/find/',$scope.find).success(function (response) {
            console.log(response);
            $scope.faults = response;


        });

        // console.log($("#beginTime").val());
    };


    $scope.setFaultId = function (_id) {
        // $scope.test = test;
        console.log(_id)
        $cookieStore.put("faultId", _id);
        window.location.href = 'project_detail.html#tab-1'

    }

    //编辑故障跳转
    $scope.editFault = function (_id) {
        console.log("editID  " + _id);
        $cookieStore.put("editFaultId",_id);
        window.location.href = 'editFault.html';
    }

    $scope.setFaultIdToDelete = function (_id,index) {
        console.log("需要删除id "+_id);
        $cookieStore.put("deleteFaultId", _id);

        $scope.toDeleteFault = $scope.allFaults[$scope.p_current-1][index];

    }

    // $scope.updateFault = function () {
    //     var id = $routeParams.id;
    //     $scope.fault.imageName = $scope.imageName;
    //
    //     $http.put('api/faults/'+id,$scope.fault).success(function (response) {
    //         window.location.href='#/faults';
    //     });
    // }










}]);
